#include "../Base/stdafx.h"
#include "Time.h"
#include "Timer.h"
#include <Boost/foreach.hpp>

Timer::Timer(int hour, int minute, int secondes)
{
	m_TimeDur = time_duration(hour, minute, secondes);
	m_EndTime = TIME->GetPTime() + m_TimeDur;
}

Timer::Timer(const time_duration& time)
{
	m_TimeDur = time;
	m_EndTime = TIME->GetPTime() +  m_TimeDur;
}

Timer::~Timer()
{
}

void Timer::AddListener(TimerCallable *caller)
{
	m_Callers.push_back(caller);
}

void Timer::Tick(float dTime)
{
	if(m_EndTime == TIME->GetPTime())
		BOOST_FOREACH(TimerCallable* caller, m_Callers) caller->CallAction(this);
}

time_duration Timer::GetResTimeDur()
{
	time_period tp = time_period(TIME->GetPTime(), m_EndTime);
	return tp.length();
}

void Timer::Reset()
{
	m_EndTime = TIME->GetPTime() +  m_TimeDur;
}

tstring Timer::GetResTime()
{
	return to_simple_wstring(GetResTimeDur());
}